package com.foreknow.demo4;

import java.util.Scanner;

public class Example {
    public static void login(int userid,int password,double balance){
        String answer = "y";
        int i  = 0;
        System.out.println("——————————————————————————");
        System.out.println("******   欢迎登录   ******");
        System.out.println("*****  中国人民银行  *****");
        System.out.println("*****    版本1.0    ******");
        System.out.println("——————————————————————————");
        Scanner input = new Scanner(System.in);
        while (i < 3){
            System.out.println("请输入账号：");
            int inputid = input.nextInt();
            System.out.println("请输入密码：");
            int inputpassword = input.nextInt();
            if (userid == inputid && password ==  inputpassword){
                i = 3;
                System.out.println("登陆成功！");
                do {
                    System.out.println("1.查询余额\t2.存款\t3.取款\t4.修改密码\t5.退出");
                    System.out.println("请选择服务：");
                    int choice = input.nextInt();
                    switch (choice){
                        case 1:
                            System.out.println("您的余额为"+balance);
                            break;
                        case 2:
                            System.out.println("请输入您要存款的金额：");
                            double cmoney = input.nextDouble();
                            if (cmoney > 0)
                            {
                                if (cmoney % 100 == 0){
                                    if (cmoney < 10000){
                                        balance = balance + cmoney;
                                        System.out.println("存款成功，当前余额为"+balance);
                                    }
                                    else {
                                        System.out.println("单次存款金额超过10000元");
                                        System.out.println("是否继续(y/n):");
                                        answer = input.next();
                                        if ("y".equals(answer)){
                                            balance = balance + cmoney;
                                            System.out.println("存款成功，当前余额为"+balance);
                                        }
                                        else {
                                            System.out.println("存款失败！");
                                            break;
                                        }
                                    }
                                }
                                else {
                                    System.out.println("请输入100的整数倍金额");
                                }
                            }
                            else {
                                System.out.println("存款金额错误！");
                            }
                            break;
                        case 3:
                            System.out.println("请输入您要取款的金额：");
                            double qmoney = input.nextDouble();
                            if (qmoney < balance)
                            {
                                if (qmoney > 0)
                                {
                                    if (qmoney % 100 == 0){
                                        if (qmoney < 3000){
                                            balance = balance - qmoney;
                                            System.out.println("取款成功，当前余额为"+balance);
                                        }
                                        else {
                                            System.out.println("单次取款金额超过3000元");
                                            System.out.println("是否继续(y/n):");
                                            answer = input.next();
                                            if ("y".equals(answer)){
                                                balance = balance - qmoney;
                                                System.out.println("取款成功，当前余额为"+balance);
                                            }
                                            else {
                                                System.out.println("取款失败！");
                                                break;
                                            }
                                        }
                                    }
                                    else {
                                        System.out.println("请输入100的整数倍金额");
                                    }
                                }
                                else {
                                    System.out.println("存款金额错误！");
                                }
                            }
                            else
                                System.out.println("余额不足！");
                            break;
                        case 4:
                            System.out.println("请输入旧密码：");
                            int oldpass = input.nextInt();
                            if (oldpass == password) {
                                System.out.println("请输入新密码：");
                                int newpass1 = input.nextInt();
                                System.out.println("请再次输入新密码：");
                                int newpass2 = input.nextInt();
                                if (newpass1 == newpass2){
                                    password = newpass1 = newpass2;
                                    System.out.println("密码修改成功！");
                                    System.out.println("当前密码为："+password);
                                }
                                else {
                                    System.out.println("两次输入密码不一致，请重新输入！");
                                    System.out.println("当前密码为："+password);
                                }
                            }
                            else {
                                System.out.println("旧密码错误！");
                            }
                            break;
                        case 5:
                            System.out.println("退出成功！");
                            return;
                    }
                    System.out.println("是否继续(y/n):");
                    answer = input.next();
                }while ("y".equals(answer));
            }
            else {
                if (i <= 1) {
                    System.out.println("账户名或密码输入错误，请重新输入！今日还剩余"+(2-i)+"次机会");
                    i++;
                }
                else{
                    System.out.println("密码错误三次，吞卡，请寻找工作人员处理！");
                    return;
                }
            }
        }
    }
    public static void main(String[] args) {
            int userid = 123;
            int password = 1234;
            double balance = 5000;
            login(userid,password,balance);
    }
}